package org.activequant.math.simulation;

import java.util.Iterator;
import java.util.Random;
/**
 * GaussianRandomGenerator implements Iterator&lt;Double&gt;<br/>
 * Holds the following associated variables:
 * <ul>
 * <li>random(Random)</li>
 * <li>sigmaSqrt(double)</li>
 * </ul>
 * @author Dimitar
 *
 */
public class GaussianRandomGenerator implements Iterator<Double> {
	/**
	 * private final Random random;
	 */
	private final Random random;
	/**
	 * constructs a GaussianRandomGenerator(implements Iterator&lt;Double&gt;) and initializes its associated
	 * random(Random) with a new Random instance.
	 */
	public GaussianRandomGenerator() {
		random = new Random();
	}
	/**
	 * constructs a GaussianRandomGenerator(implements Iterator&lt;Double&gt;) using the given seed(long)
	 * to set its associated random(Random) with a new Random using that seed.
	 * @param seed
	 */
	public GaussianRandomGenerator(long seed) {
		random = new Random(seed);
	}
	/**
	 * private double sigmaSqrt = 1.0;
	 */
	private double sigmaSqrt = 1.0;
	/**
	 * sets the associated sigmaSqrt(double) with the square root of the given val(double)
	 * @param val
	 */
	public void setSigma(double val) {
		sigmaSqrt = Math.sqrt(val);
	}
	/**
	 * returns ${sigmaSqrt} * ${sigmaSqrt}<br/>
	 * , using the associated sigmaSqrt(double)
	 * @return
	 */
	public double getSigma() {
		return sigmaSqrt * sigmaSqrt;
	}
	/**
	 * returns true
	 */
	public boolean hasNext() {
		return true;
	}
	/**
	 * returns ${random.nextGaussian()} * ${sigmaSqrt}<br/>
	 * , using the associated random(Random) and sigmaSqrt(double)
	 */
	public Double next() {
		return random.nextGaussian() * sigmaSqrt;
	}
	/**
	 * throws an UnsupportedOperationException
	 */
	public void remove() {
		throw new UnsupportedOperationException();
	}
}
